package com.cwd.arm.application.service.read;

import com.cwd.arm.infrastructure.dao.ProjectReceiveDirectorDao;
import com.cwd.arm.infrastructure.po.ProjectReceiveDirectorPo;
import com.cwd.arm.application.dto.ProjectReceiveDirectorDto;
import com.cwd.arm.application.service.read.facade.ProjectReceiveDirectorReadService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.stream.Collectors;

/**
* Description:项目收款负责人
* Created on 2022年01月15日
* @author  yan
*/
@Repository
@Primary
public class ProjectReceiveDirectorReadServiceImpl implements ProjectReceiveDirectorReadService {

    @Autowired
    private ProjectReceiveDirectorDao projectReceiveDirectorDao;

    @Override
    public List<ProjectReceiveDirectorDto> selectByProjectId(Long projectId) {
        List<ProjectReceiveDirectorPo>  poList = projectReceiveDirectorDao.selectListByProjectId(projectId);
        return convertToDtoList(poList);
    }

    private ProjectReceiveDirectorDto convertToDto(ProjectReceiveDirectorPo po){
        ProjectReceiveDirectorDto dto = new ProjectReceiveDirectorDto();
        BeanUtils.copyProperties(po, dto);
        return dto;
    }

    private List<ProjectReceiveDirectorDto> convertToDtoList(List<ProjectReceiveDirectorPo> poList){
        return poList.stream().map(po->convertToDto(po)).collect(Collectors.toList());
    }

}
